﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<style type="text/css">
    .ui-jqgrid .ui-jqgrid-pager .ui-pager-table,
    .ui-jqgrid .ui-jqgrid-toppager .ui-pager-table {
        width: 95%;
    }
</style>
<script type="text/javascript">
    var currentList = @Html.Raw(ViewBag.companys)
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        $('#infoTab1').addClass("active");
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetProductionSumManageJson?FProductionNO=@ViewBag.number",
            height: 190,
            colModel: [
                { label: '车型编码', name: 'FProductNO', width: 180, align: 'left', sortable: false },
                { label: '车型名称', name: 'FProductName', width: 200, align: 'left', sortable: false },
                { label: '使用件数', name: 'ProductSum', width: 60, align: 'right', sortable: false }
            ],
            viewrecords: true,
            rowNum: 10000000,
            rownumWidth: 40,
            ondblClickRow: function (rowid) {
                
            },
            gridComplete: function () {

            },
            loadComplete: function () {
                
            },
            onSelectRow: function (rowid) {

            },
            onPaging: function (page_btn) {
                
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { FProductionNO: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function findElement(arrayToSearch, attr, val) {
        for (var i = 0; i < arrayToSearch.length; i++) {
            if (arrayToSearch[i][attr] == val) {
                return i;
            }
        }
        return -1;
    }
    function btn_ok() {
        var valArray = [];
        $('.product_sum').each(function () {
            var text = $(this).find('th.formTitle').text();
            var id = "ProductSum" + $(this).find('td.formValue input[type="text"]').prop("id");
            var value = $(this).find('td.formValue input[type="text"]').val();
            var oldvalue = $(this).find('td.formValue input[type="hidden"]').val();
            if (value != oldvalue) {
                //alert(text + ',' + value + ',' + oldvalue + ',' + id);
                valArray.push({id: id, value: value});
            }
        });
        if (valArray.length > 0) {
            var FProductionNO = $('#txt_number').val();
            var values = JSON.stringify(valArray);
            //$.submitForm({
            //    url: "/BOM/Manufacture/SubmitProductionSumManage",
            //    param: { FProductionNO: FProductionNO, values: values },
            //    close: false,
            //    success: function () {
            //        $.reload();
            //    }
            //})
            var father = $.currentSubSubWindow().frames["Detail"];
            father.do_productionsum(values);
            
        } else {
            $.modalAlert("没有做任何修改。", "warning");
        }


        //parent.$.detailClose();
    }
    function btn_cancel() {
        var father = $.currentSubSubWindow().frames["Detail"];
        father.$.detailCloseTop();
    }
</script>
<div id="layout" style="height: 100%; width: 100%; ">
    <div style="padding: 8px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">
        <label class="prefix">零件编号</label> <input id="txt_number" type="text" class="form-control" disabled="disabled" value="@ViewBag.number" /> &nbsp;
        <label class="prefix">零件名称</label> <input id="txt_name" type="text" class="form-control input-width-185" disabled="disabled" value="@ViewBag.name" /> &nbsp;
        <div class="btn-group" style="">
            <a id="btn_ok" class="btn btn-primary center-block btn-1" onclick="btn_ok();"><span class="glyphicon glyphicon-ok"></span> 保存</a>
        </div>
        <div class="btn-group" style="">
            <a id="btn_cancel" class="btn btn-primary center-block btn-1" onclick="btn_cancel();"><span class="glyphicon glyphicon-remove"></span> 取消</a>
        </div>
    </div>
    <div>
        <ul id="myTab" class="nav nav-tabs" style="">
        @for (int i = 0; i < ViewBag.groupList.Count; i++)
        {
            if (i == 0)
            {
                <li class="active"><a href="@Html.Raw("#infoTab" + (i+1).ToString())" data-toggle="tab">@ViewBag.groupList[i].title</a></li>
            }
            else
            {
            <li><a href="@Html.Raw("#infoTab" + (i+1).ToString())" data-toggle="tab">@ViewBag.groupList[i].title</a></li>
            }
        }
        </ul>
        <div id="myTabContent" class="tab-content" style="padding-top:5px;">
        @for (int i = 0; i < ViewBag.groupList.Count; i++)
        {
            <div class="tab-pane fade in" id="@Html.Raw("infoTab" + (i + 1).ToString())">
                
                <div style="width: 820px; margin-left: 5px;">
                    @foreach (var item in ViewBag.groupList[i].list)
                    { 
                    <div style="width:160px;float:left;">
                    <table class="form product_sum" style="">
                        <tr>
                        <th class="formTitle" style="width:100px;overflow:hidden;">@item.FProductNO</th>
                        <td class="formValue" style="width:60px;">
                            <input id="@item.FOrderNum.ToString().PadLeft(3,'0')" name="" type="text" class="form-control text-right digits" value="@item.ProductSum" />
                            <input id="" name="" type="hidden" value="@item.ProductSum" />
                        </td>
                        </tr>
                    </table>
                    </div>
                    }
                </div>
            </div>
        }
        </div>
    </div>
</div>

